using System;
using EPiServer.Common;
using EPiServer.Common.Publishing;
using EPiServer.Community.VideoGallery;
using EPiServer.Community.VideoGallery.Queries;

namespace EPiAbstractions.Community.VideoGallery
{
    public class VideoGalleryHandlerFacade : IVideoGalleryHandlerFacade
    {
        private static VideoGalleryHandlerFacade _instance;

        public VideoGalleryHandlerFacade()
        {
            VideoGalleryHandler.VideoAdded += OnVideoAdded;
            VideoGalleryHandler.VideoUpdated += OnVideoUpdated;
            VideoGalleryHandler.VideoRemoved += OnVideoRemoved;
            VideoGalleryHandler.VideoGalleryAdded += OnVideoGalleryAdded;
            VideoGalleryHandler.VideoGalleryUpdated += OnVideoGalleryUpdated;
            VideoGalleryHandler.VideoGalleryRemoved += OnVideoGalleryRemoved;
            VideoGalleryHandler.VideoCommentAdded += OnVideoCommentAdded;
            VideoGalleryHandler.VideoCommentUpdated += OnVideoCommentUpdated;
            VideoGalleryHandler.VideoCommentRemoved += OnVideoCommentRemoved;
        }

        public static VideoGalleryHandlerFacade Instance
        {
            get
            {
                if (_instance == null)
                    _instance = new VideoGalleryHandlerFacade();

                return _instance;
            }

            set { _instance = value; }
        }

        #region IVideoGalleryHandlerFacade Members

        public event EPiServerCommonEventHandler VideoAdded;
        public event EPiServerCommonEventHandler VideoUpdated;
        public event EPiServerCommonEventHandler VideoRemoved;
        public event EPiServerCommonEventHandler VideoGalleryAdded;
        public event EPiServerCommonEventHandler VideoGalleryUpdated;
        public event EPiServerCommonEventHandler VideoGalleryRemoved;
        public event EPiServerCommonEventHandler VideoCommentAdded;
        public event EPiServerCommonEventHandler VideoCommentUpdated;
        public event EPiServerCommonEventHandler VideoCommentRemoved;

        public virtual EPiServer.Community.VideoGallery.VideoGallery AddVideoGallery(
            EPiServer.Community.VideoGallery.VideoGallery videoGallery)
        {
            return VideoGalleryHandler.AddVideoGallery(videoGallery);
        }

        public virtual void UpdateVideoGallery(EPiServer.Community.VideoGallery.VideoGallery videoGallery)
        {
            VideoGalleryHandler.UpdateVideoGallery(videoGallery);
        }

        public virtual void RemoveVideoGallery(EPiServer.Community.VideoGallery.VideoGallery videoGallery)
        {
            VideoGalleryHandler.RemoveVideoGallery(videoGallery);
        }

        public virtual EPiServer.Community.VideoGallery.VideoGallery GetVideoGallery(Int32 id)
        {
            return VideoGalleryHandler.GetVideoGallery(id);
        }

        public virtual VideoGalleryCollection GetVideoGalleryChildren(EPiServer.Community.VideoGallery.VideoGallery parent)
        {
            return VideoGalleryHandler.GetVideoGalleryChildren(parent);
        }

        public virtual Video AddVideo(Video video)
        {
            return VideoGalleryHandler.AddVideo(video);
        }

        public virtual void UpdateVideo(Video video)
        {
            VideoGalleryHandler.UpdateVideo(video);
        }

        public virtual void RemoveVideo(Video video)
        {
            VideoGalleryHandler.RemoveVideo(video);
        }

        public virtual Video GetVideo(Int32 id)
        {
            return VideoGalleryHandler.GetVideo(id);
        }

        public virtual Video GetVideo(Guid cdnId)
        {
            return VideoGalleryHandler.GetVideo(cdnId);
        }

        public virtual VideoCollection GetVideos(VideoGalleryCollection galleries, Int32 page, Int32 pageSize, VideoSortOrder[] sortOrder)
        {
            return VideoGalleryHandler.GetVideos(galleries, page, pageSize, sortOrder);
        }

        public virtual VideoCollection GetVideos(VideoGalleryCollection galleries, Int32 page, Int32 pageSize, out Int32 totalItems,
                                                 VideoSortOrder[] sortOrder)
        {
            return VideoGalleryHandler.GetVideos(galleries, page, pageSize, out totalItems, sortOrder);
        }

        public virtual VideoCollection GetVideos(VideoGalleryCollection galleries, Int32 page, Int32 pageSize,
                                                 ProcessingStage processingStage, out Int32 totalItems, VideoSortOrder[] sortOrder)
        {
            return VideoGalleryHandler.GetVideos(galleries, page, pageSize, processingStage, out totalItems, sortOrder);
        }

        public virtual VideoCollection GetVideos(VideoGalleryCollection galleries, Int32 page, Int32 pageSize, PublishState publishState,
                                                 out Int32 totalItems, VideoSortOrder[] sortOrder)
        {
            return VideoGalleryHandler.GetVideos(galleries, page, pageSize, publishState, out totalItems, sortOrder);
        }

        public virtual VideoCollection GetVideos(VideoGalleryCollection galleries, Int32 page, Int32 pageSize,
                                                 ProcessingStage processingStage, PublishState publishState, out Int32 totalItems,
                                                 VideoSortOrder[] sortOrder)
        {
            return VideoGalleryHandler.GetVideos(galleries, page, pageSize, processingStage, publishState, out totalItems, sortOrder);
        }

        public virtual VideoCollection GetVideos(VideoGalleryCollection galleries, Int32 page, Int32 pageSize,
                                                 ProcessingStage processingStage, PublishState publishState, Boolean ignoreCache,
                                                 out Int32 totalItems, VideoSortOrder[] sortOrder)
        {
            return VideoGalleryHandler.GetVideos(galleries, page, pageSize, processingStage, publishState, ignoreCache, out totalItems,
                                                 sortOrder);
        }

        public virtual VideoCollection GetVideos(VideoGalleryCollection galleries, Int32 page, Int32 pageSize,
                                                 ProcessingStage processingStage, PublishState publishState, Boolean ignoreCache,
                                                 TimeSpan? explicitCacheTime, out Int32 totalItems, VideoSortOrder[] sortOrder)
        {
            return VideoGalleryHandler.GetVideos(galleries, page, pageSize, processingStage, publishState, ignoreCache, explicitCacheTime,
                                                 out totalItems, sortOrder);
        }

        public virtual VideoCollection GetQueryResult(VideoQuery query)
        {
            return VideoGalleryHandler.GetQueryResult(query);
        }

        public virtual VideoCollection GetQueryResult(VideoQuery query, Int32 page, Int32 pageSize)
        {
            return VideoGalleryHandler.GetQueryResult(query, page, pageSize);
        }

        public virtual VideoCollection GetQueryResult(VideoQuery query, Int32 page, Int32 pageSize, out Int32 totalItems)
        {
            return VideoGalleryHandler.GetQueryResult(query, page, pageSize, out totalItems);
        }

        public virtual VideoGalleryCollection GetQueryResult(VideoGalleryQuery query)
        {
            return VideoGalleryHandler.GetQueryResult(query);
        }

        public virtual VideoGalleryCollection GetQueryResult(VideoGalleryQuery query, Int32 page, Int32 pageSize)
        {
            return VideoGalleryHandler.GetQueryResult(query, page, pageSize);
        }

        public virtual VideoGalleryCollection GetQueryResult(VideoGalleryQuery query, Int32 page, Int32 pageSize, out Int32 totalItems)
        {
            return VideoGalleryHandler.GetQueryResult(query, page, pageSize, out totalItems);
        }

        public virtual VideoCommentCollection GetQueryResult(VideoCommentQuery query)
        {
            return VideoGalleryHandler.GetQueryResult(query);
        }

        public virtual VideoCommentCollection GetQueryResult(VideoCommentQuery query, Int32 page, Int32 pageSize)
        {
            return VideoGalleryHandler.GetQueryResult(query, page, pageSize);
        }

        public virtual VideoCommentCollection GetQueryResult(VideoCommentQuery query, Int32 page, Int32 pageSize, out Int32 totalItems)
        {
            return VideoGalleryHandler.GetQueryResult(query, page, pageSize, out totalItems);
        }

        public virtual VideoComment AddVideoComment(VideoComment videoComment)
        {
            return VideoGalleryHandler.AddVideoComment(videoComment);
        }

        public virtual VideoComment GetVideoComment(Int32 id)
        {
            return VideoGalleryHandler.GetVideoComment(id);
        }

        public virtual VideoCommentCollection GetVideoComments(Video video, Int32 page, Int32 pageSize, VideoCommentSortOrder[] sortOrder)
        {
            return VideoGalleryHandler.GetVideoComments(video, page, pageSize, sortOrder);
        }

        public virtual VideoCommentCollection GetVideoComments(Video video, Int32 page, Int32 pageSize, out Int32 totalItems,
                                                               VideoCommentSortOrder[] sortOrder)
        {
            return VideoGalleryHandler.GetVideoComments(video, page, pageSize, out totalItems, sortOrder);
        }

        public virtual void UpdateVideoComment(VideoComment videoComment)
        {
            VideoGalleryHandler.UpdateVideoComment(videoComment);
        }

        public virtual void RemoveVideoComment(VideoComment videoComment)
        {
            VideoGalleryHandler.RemoveVideoComment(videoComment);
        }

        #endregion

        public virtual void OnVideoAdded(String sender, EPiServerCommonEventArgs e)
        {
            if (VideoAdded != null)
                VideoAdded(sender, e);
        }

        public virtual void OnVideoUpdated(String sender, EPiServerCommonEventArgs e)
        {
            if (VideoUpdated != null)
                VideoUpdated(sender, e);
        }

        public virtual void OnVideoRemoved(String sender, EPiServerCommonEventArgs e)
        {
            if (VideoRemoved != null)
                VideoRemoved(sender, e);
        }

        public virtual void OnVideoGalleryAdded(String sender, EPiServerCommonEventArgs e)
        {
            if (VideoGalleryAdded != null)
                VideoGalleryAdded(sender, e);
        }

        public virtual void OnVideoGalleryUpdated(String sender, EPiServerCommonEventArgs e)
        {
            if (VideoGalleryUpdated != null)
                VideoGalleryUpdated(sender, e);
        }

        public virtual void OnVideoGalleryRemoved(String sender, EPiServerCommonEventArgs e)
        {
            if (VideoGalleryRemoved != null)
                VideoGalleryRemoved(sender, e);
        }

        public virtual void OnVideoCommentAdded(String sender, EPiServerCommonEventArgs e)
        {
            if (VideoCommentAdded != null)
                VideoCommentAdded(sender, e);
        }

        public virtual void OnVideoCommentUpdated(String sender, EPiServerCommonEventArgs e)
        {
            if (VideoCommentUpdated != null)
                VideoCommentUpdated(sender, e);
        }

        public virtual void OnVideoCommentRemoved(String sender, EPiServerCommonEventArgs e)
        {
            if (VideoCommentRemoved != null)
                VideoCommentRemoved(sender, e);
        }
    }
}